﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

using Global.Class.Library;

namespace DataTransferObject
{
    public class GCGBWHOutputCollection : NotifyPropertyChangeObject
    {
        private int gcgbCommandSerialID;
        private int materialSetID;
        private double gcgbCommandQuantity;
        private double remainsQuantity;        
        private double quantity;
        private double quantityLoss;
        
        private int materialSemiID1;
        private double quantityPerSet1;
        private double quantitySemiBad1;
        private double quantitySemiLoss1;
        
        private int materialSemiID2;
        private double quantityPerSet2;
        private double quantitySemiBad2;
        private double quantitySemiLoss2;

        private int materialSemiID3;
        private double quantityPerSet3;
        private double quantitySemiBad3;
        private double quantitySemiLoss3;

        private string remarks;


        public GCGBWHOutputCollection()
            : this(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "")
        {
        }

        public GCGBWHOutputCollection(int gcgbCommandSerialID, int materialSetID, double gcgbCommandQuantity, double remainsQuantity, double quantity, double quantityLoss, int materialSemiID1, double quantityPerSet1, double quantitySemiBad1, double quantitySemiLoss1, int materialSemiID2, double quantityPerSet2, double quantitySemiBad2, double quantitySemiLoss2, int materialSemiID3, double quantityPerSet3, double quantitySemiBad3, double quantitySemiLoss3, string remarks)
        {
            GlobalDefaultValue.Apply(this);

            this.GCGBCommandSerialID = gcgbCommandSerialID;
            this.MaterialSetID = materialSetID;
            this.GCGBCommandQuantity = gcgbCommandQuantity;
            this.RemainsQuantity = remainsQuantity;            
            this.Quantity = quantity;
            this.QuantityLoss = quantityLoss;

            this.MaterialSemiID1 = materialSemiID1;
            this.QuantityPerSet1 = quantityPerSet1;
            this.QuantitySemiBad1 = quantitySemiBad1;
            this.QuantitySemiLoss1 = quantitySemiLoss1;            

            this.MaterialSemiID2 = materialSemiID2;
            this.QuantityPerSet2 = quantityPerSet2;
            this.QuantitySemiBad2 = quantitySemiBad2;
            this.QuantitySemiLoss2 = quantitySemiLoss2;

            this.MaterialSemiID3 = materialSemiID3;
            this.QuantityPerSet3 = quantityPerSet3;
            this.QuantitySemiBad3 = quantitySemiBad3;
            this.QuantitySemiLoss3 = quantitySemiLoss3;
 
            this.Remarks = remarks;
        }


        #region Properties

        [DefaultValue(0)]
        public int GCGBCommandSerialID
        {
            get { return this.gcgbCommandSerialID; }
            set { ApplyPropertyChange<GCGBWHOutputCollection, int>(ref this.gcgbCommandSerialID, o => o.GCGBCommandSerialID, value); }
        }

        
        [DefaultValue(0)]
        public int MaterialSetID
        {
            get { return this.materialSetID; }
            set { ApplyPropertyChange<GCGBWHOutputCollection, int>(ref this.materialSetID, o => o.MaterialSetID, value); }
        }

        [DefaultValue(0)]
        public double GCGBCommandQuantity
        {
            get { return this.gcgbCommandQuantity; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBWHOutputCollection, double>(ref this.gcgbCommandQuantity, o => o.GCGBCommandQuantity, value);
            }
        }

        [DefaultValue(0)]
        public double RemainsQuantity
        {
            get { return this.remainsQuantity; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBWHOutputCollection, double>(ref this.remainsQuantity, o => o.RemainsQuantity, value);
            }
        }

        [DefaultValue(0)]
        public double Quantity
        {
            get { return this.quantity; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBWHOutputCollection, double>(ref this.quantity, o => o.Quantity, value);
            }
        }

        [DefaultValue(0)]
        public double QuantityLoss
        {
            get { return this.quantityLoss; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBWHOutputCollection, double>(ref this.quantityLoss, o => o.QuantityLoss, value);
            }
        }


        [DefaultValue(0)]
        public int MaterialSemiID1
        {
            get { return this.materialSemiID1; }
            set { ApplyPropertyChange<GCGBWHOutputCollection, int>(ref this.materialSemiID1, o => o.MaterialSemiID1, value); }
        }

        [DefaultValue(0)]
        public double QuantityPerSet1
        {
            get { return this.quantityPerSet1; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBWHOutputCollection, double>(ref this.quantityPerSet1, o => o.QuantityPerSet1, value);
            }
        }

        [DefaultValue(0)]
        public double QuantitySemi1
        {
            get { return this.Quantity * this.QuantityPerSet1; }
        }

        [DefaultValue(0)]
        public double QuantitySemiBad1
        {
            get { return this.quantitySemiBad1; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBWHOutputCollection, double>(ref this.quantitySemiBad1, o => o.QuantitySemiBad1, value);
            }
        }

        [DefaultValue(0)]
        public double QuantitySemiLoss1
        {
            get { return this.quantitySemiLoss1; }
            set { ApplyPropertyChange<GCGBWHOutputCollection, double>(ref this.quantitySemiLoss1, o => o.QuantitySemiLoss1, value); }
        }        

        [DefaultValue(0)]
        public int MaterialSemiID2
        {
            get { return this.materialSemiID2; }
            set { ApplyPropertyChange<GCGBWHOutputCollection, int>(ref this.materialSemiID2, o => o.MaterialSemiID2, value); }
        }

        [DefaultValue(0)]
        public double QuantityPerSet2
        {
            get { return this.quantityPerSet2; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBWHOutputCollection, double>(ref this.quantityPerSet2, o => o.QuantityPerSet2, value);
            }
        }

        [DefaultValue(0)]
        public double QuantitySemi2
        {
            get { return this.Quantity * this.QuantityPerSet2; }
        }

        [DefaultValue(0)]
        public double QuantitySemiBad2
        {
            get { return this.quantitySemiBad2; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBWHOutputCollection, double>(ref this.quantitySemiBad2, o => o.QuantitySemiBad2, value);
            }
        }

        [DefaultValue(0)]
        public double QuantitySemiLoss2
        {
            get { return this.quantitySemiLoss2; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBWHOutputCollection, double>(ref this.quantitySemiLoss2, o => o.QuantitySemiLoss2, value);
            }
        }      

        [DefaultValue(0)]
        public int MaterialSemiID3
        {
            get { return this.materialSemiID3; }
            set { ApplyPropertyChange<GCGBWHOutputCollection, int>(ref this.materialSemiID3, o => o.MaterialSemiID3, value); }
        }

        [DefaultValue(0)]
        public double QuantityPerSet3
        {
            get { return this.quantityPerSet3; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBWHOutputCollection, double>(ref this.quantityPerSet3, o => o.QuantityPerSet3, value);
            }
        }

        [DefaultValue(0)]
        public double QuantitySemi3
        {
            get { return this.Quantity * this.QuantityPerSet3; }
        }

        [DefaultValue(0)]
        public double QuantitySemiBad3
        {
            get { return this.quantitySemiBad3; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBWHOutputCollection, double>(ref this.quantitySemiBad3, o => o.QuantitySemiBad3, value);
            }
        }

        [DefaultValue(0)]
        public double QuantitySemiLoss3
        {
            get { return this.quantitySemiLoss3; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBWHOutputCollection, double>(ref this.quantitySemiLoss3, o => o.QuantitySemiLoss3, value);
            }
        }    

        [DefaultValue("")]
        public string Remarks
        {
            get { return this.remarks; }
            set { ApplyPropertyChange<GCGBWHOutputCollection, string>(ref this.remarks, o => o.Remarks, value); }
        }

        #endregion

        protected override System.Collections.Generic.List<ValidationRule> CreateRules()
        {
            List<ValidationRule> validationRules = base.CreateRules();
            validationRules.Add(new SimpleValidationRule("Quantity", "Over remainning quantity.", delegate { return this.Quantity <= this.RemainsQuantity; }));
            validationRules.Add(new SimpleValidationRule("QuantitySemiLoss1", "Over quantity semi 1.", delegate { return this.QuantitySemiBad1 + this.QuantitySemiLoss1 <= this.QuantitySemi1; }));
            validationRules.Add(new SimpleValidationRule("QuantitySemiLoss2", "Over quantity semi 2.", delegate { return this.QuantitySemiBad2 + this.QuantitySemiLoss2 <= this.QuantitySemi2; }));
            validationRules.Add(new SimpleValidationRule("QuantitySemiLoss3", "Over quantity semi 3.", delegate { return this.QuantitySemiBad3 + this.QuantitySemiLoss3 <= this.QuantitySemi3; }));

            return validationRules;
        }

    }
}
